import request from '@/common/utils/request_custom.js'


export const userLogin = (data) => {
  request.isPayBaseUrl = false
  console.log("请求信息:", {
    ...data
  })
  return request.post('/users/login-wxmini', data)
}

export const queryDeviceInfo = (sn) => {
  request.isPayBaseUrl = false
  return request.get(`/devices?sn=${sn}`)
}

export const getProducts = (deviceId) => {
  request.isPayBaseUrl = false
  return request.get(`/devices/${deviceId}/items`)
}

export const getUserCoupons = (operator_id) => {
  request.isPayBaseUrl = false
  return request.get(`/operators/${operator_id}/coupons`)
}

// export const getUserAlreadyReceivedCoupon = (operator_id) => {
//   request.isPayBaseUrl = false
//   return request.get(`/operators/${operator_id}/coupons`)
// }

export const postGetCoupon = (coupon_id) => {
  request.isPayBaseUrl = false
  return request.post(`/coupons/${coupon_id}/tickets`)
}

/**
 * params {}
 * @param products  格式: id,id 商品id使用逗号相隔
 * @param devices   deviceId  设备ID
 */
export const queryUserAllCoupon = (operator_id, params = {}) => {
  request.isPayBaseUrl = false
  return request.get(`/operators/${operator_id}/tickets`, params)
}


export const createOrder = (data) => {
  request.isPayBaseUrl = false
  return request.post('/orders', data)
}
export const updateOrderState = (order_id, state) => {
  request.isPayBaseUrl = false
  return request.put(`/orders/${order_id}/status`, {
    "status": state
  })
}

export const getPayInfo = (order_id, scene = "wx-mini") => {
  request.isPayBaseUrl = false
  return request.post('/pay', {
    order_id: order_id,
    scene: scene,
  })
}
/**
 * params
 * @param status 订单状态
 * @param page   页码
 */
export const queryOrders = (params) => {
  request.isPayBaseUrl = false
  return request.get('/orders', params)
}

export const queryUserInfo = (user_id) => {
  request.isPayBaseUrl = false
  return request.get(`/users/${user_id}`)
}